<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Pcode System</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/misc/adminlte-2.3.7/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/misc/adminlte-2.3.7/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="/misc/adminlte-2.3.7/dist/css/skins/skin-purple.min.css">
    <link rel="stylesheet" href="/misc/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/misc/app/css/base.css">
    <style>
        .login-page, .register-page {
            background: #57a2ce;
        }

        .login-box-body, .register-box-body {
            border-radius: 5px;
            box-shadow: 0 0px 40px rgba(0, 0, 0, 0.5);
        }

        .login-logo a, .register-logo a {
            color: #fff;
        }
    </style>
</head>

<body class="hold-transition login-page">
<div class="login-box">
    <div class="login-logo">
        <a href="/">Pcode System</a>
    </div>
    <div class="login-box-body">
        <p class="login-box-msg">请输入您的登录账号</p>
        <form name="loginForm">
            <div class="form-group has-feedback">
                <input type="text" class="form-control" placeholder="账号" name="ipt_account"/>
                <span class="glyphicon glyphicon-user form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input type="password" class="form-control" placeholder="密码" name="ipt_pwd"/>
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="row" id="loginId" >
                <div class="col-xs-12" >
                    <button type="button" class="btn btn-primary btn-block" name="btn_login">登录</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/misc/adminlte-2.3.7/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="/misc/adminlte-2.3.7/bootstrap/js/bootstrap.min.js"></script>
<script src="/misc/bootbox.min.js"></script>

<script src="/misc/app/js/base.js"></script>

<script>
    var form = document.loginForm;
    $(function () {
        $(form.btn_login).click(function () {
            login();
        });
        
        
    });
    $(function(){ 
    	$(document).keydown(function(event){ 
    	if(event.keyCode==13){ 
    	  $("#loginId").click(); 
    	} 
      }); 
    	
    });
    $("#loginId").click(function(){ 
		 login();
	}); 
		
    function login() {
        var account = form.ipt_account.value;
        var pwd = form.ipt_pwd.value;

        if (!/.+/.test(account) || !/.+/.test(pwd)) {
            bootbox.balert("请输入您的账号和密码");
            return;
        }

  //      $.post("/login", {"account": account, "pwd": pwd}, function () {
  //          window.location = "/";
  //      });
        
        
        jQuery.ajax({
            type:'post',
            url:'/login',
            data:{"account": account, "pwd": pwd},
            dataType:'json',
            cache:false,
            success:function(data){
            	var code = data.code;
            	if(code==1){
            		 window.location = "/";
            	}else{
            		tipper.danger(data.msg);
            	}
            },
            error:function () {
                tipper.danger("登录出错！");
            }
       });
        
        
        
    }
</script>
</body>
</html>